// defHttp就是封装好的发送请求函数
import { defHttp } from '/@/utils/http/axios';
// 数据类型 - 定义响应返回值数据的类型
import type { AttrListModel, CategoryIdsModel, AttrModel } from './model/attrModel';

// 枚举：定义请求地址的
enum Api {
  GetAttrList = '/admin/product/attrInfoList',
  SaveOrUpdateAttr = '/admin/product/saveAttrInfo',
  RemoveAttr = '/admin/product/deleteAttr',
}

// 删除属性
export const removeAttrApi = (id: number) => {
  return defHttp.delete<null>({
    url: Api.RemoveAttr,
    params: `/${id}`,
  });
};

// 获取属性列表
export const getAttrListApi = ({ category1Id, category2Id, category3Id }: CategoryIdsModel) => {
  return defHttp.get<AttrListModel>({
    url: Api.GetAttrList,
    params: `/${category1Id}/${category2Id}/${category3Id}`,
  });
};

// 添加或更新属性
export const saveOrUpdateAttrApi = (data: AttrModel) => {
  return defHttp.post<null>({
    url: Api.SaveOrUpdateAttr,
    data,
  });
};
